﻿<div class="content-top-nav">
    <div class="layui-row">
        <div class="layui-col-md11">
            <h3 style="color:#444">
                <i class="layui-icon layui-icon-home"></i>
                角色列表
            </h3>
        </div>
        <div class="layui-col-md1" style="text-align:right;">
        </div>
    </div>
    <hr>
</div>

<div class="layui-fluid" style="margin-bottom:50px;">
    <script type="text/html" id="toolbarAE">
        <div class="layui-btn-container">
            @if (await Authorizer.AuthView(PermissionKeys.UserGroup_AddOrEdit))
            {
                    <button class="layui-btn layui-btn-sm data-add-btn"><i class="layui-icon">&#xe642;</i>新增</button>
            }
        </div>
    </script>

    <table class="layui-hide" id="currentTableId" lay-data="{id: 'idReload'}" lay-filter="currentTableFilter"></table>
    <script type="text/html" id="currentTableBar">
        <div class="layui-btn-group">
            @if (await Authorizer.AuthView(PermissionKeys.UserGroup_AddOrEdit))
            {
                                <a class="layui-btn layui-btn-sm data-count-edit" lay-event="edit"><i class="layui-icon layui-icon-auz"></i>系统权限</a>
            }
          
        {{# if(d.id != 1){  }}
            @if (await Authorizer.AuthView(PermissionKeys.UserGroup_Delete))
            {
                        <a class="layui-btn layui-btn-sm layui-btn-danger data-count-delete" lay-event="delete"><i class="layui-icon">&#xe640;</i>删除</a>
            }
        {{# } }}
        </div>
    </script>

</div>

<script>
    layui.define( function () {
        var table = layui.table, $ = layui.jquery, form = layui.form;

        form.render();

        table.render({
            elem: '#currentTableId',
            //url: '/resapi/table.json',
            url: '/Admin/UserGroup/Index?json=1',
            toolbar: '#toolbarAE',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            page: {
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']//自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                , groups: 1 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
            },
            cols: [[
                { field: 'id', width: 70, title: 'ID', sort: true },
                { field: 'groupname', width: 260, title: '角色名' },
                { title: '操作', templet: '#currentTableBar', align: "left" }
            ]],
            id: 'tableReload',
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true
        });


        // 监听添加操作
        $(".data-add-btn").on("click", function () {
            loadMain('/Admin/UserGroup/AddOrEdit');
            return false;
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                loadMain('/Admin/UserGroup/AddOrEdit?id=' + data.id);
                return false;
            }else if (obj.event === 'delete') {
                layer.confirm('确定删除 名为' + data.groupname + '的角色吗？', {
                    btn: ['确定', '取消']
                }, function (index) {
                    $.post('/Admin/UserGroup/Delete?id=' + data.id, function (res) {
                        if (res.status == 1) {
                            layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                                obj.del();
                                layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, anim: 6, time: 5000 });
                        }
                    });
                });
            }
        });
        //搜索重载表格
        $('#searchBtn').on('click', function () {
            table.reloadData('tableReload', {
                method: 'get',
                where: {
                    title: $('#title').val(),
                    cid: $('#cid').val(),
                },
                page: {
                    curr: 1
                },
                page: true,
            });
            return false;
        });

    });
</script>
